import jwt
from common.config import cfg
JWT_SECRET_KEY = cfg['jwt']['secret_key']
def create_jwt_token(user_id, phonenumber,account_type):
    payload = {
        'user_id': user_id,
        'phonenumber': phonenumber,
        'account_type':account_type
    }
    return jwt.encode(payload, JWT_SECRET_KEY, algorithm='HS256')

def decode_jwt_token(token):
    try:
        return 200, jwt.decode(token, JWT_SECRET_KEY, algorithms=['HS256'])
    except jwt.ExpiredSignatureError:
        return 401, "Token has expired"
    except jwt.InvalidTokenError:
        return 401, "Invalid token"
